<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Testimonial_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		
	}
	
	function addTestimonial($data)
	{
		$this->db->insert('tb_testimonial',$data);
	}
	
	function getTestimonial($query=FALSE,$id=FALSE,$limit=FALSE,$offset=FALSE)
	{
		if(empty($query)):
			$this->db->limit($limit,$offset);
			$this->db->order_by('testi_id','desc');
			return $this->db->get('tb_testimonial')->result_array();
		elseif($query == 'enable'):
			$this->db->limit($limit,$offset);
			$this->db->where('tb_testimonial.status',2);
			$this->db->order_by('tb_testimonial.testi_id','DESC');
			$this->db->join('tb_member','tb_member.member_id = tb_testimonial.member_id');
			$this->db->select('tb_member.nama,tb_testimonial.testi_id,tb_testimonial.isi_testi,tb_testimonial.date_added');
			$this->db->order_by('testi_id','DESC');
			return $this->db->get('tb_testimonial')->result_array();
		elseif($query = 'detail'):
			$this->db->where('testi_id',$id);
			return $this->db->get('tb_testimonial')->row();
		endif;
	}
	
	function updateTestimonial($id,$data)
	{
		$this->db->where('testi_id',$id);	
		$this->db->update('tb_testimonial',$data);	
	}
	
	function deleteTestimonial($id)
	{
		$this->db->where('testi_id',$id);
		$this->db->delete('tb_testimonial');
	}
}